package com.spring.cloud.commonsecurity.tokenthread;

import jdk.nashorn.internal.parser.Token;

//让线程保存token信息
public class TokenThreadLocal {

    //ThreadLocal 声明位String型
    private final ThreadLocal<String> tokenThreadLocal = new ThreadLocal<>();

    //单例
    private static TokenThreadLocal ss = null;

    //不可被实例化
    private TokenThreadLocal(){

    }

    //线程变量保存
    public void setToken(String token){
        tokenThreadLocal.set(token);
    }

    //获取线程变量
    public String getToken(){
        return tokenThreadLocal.get();
    }

    //创建单例
    public static TokenThreadLocal get(){
        if(ss == null){
            ss = new TokenThreadLocal();
        }
        return ss;
    }
}
